//
//  UIBarButtonItem+XKL.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/4/25.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "UIBarButtonItem+XKL.h"

@implementation UIBarButtonItem (XKL)

+(instancetype)itemWithImageName:(NSString *)imageName seletImageName:(NSString *)seletImageName target:(id)target sel:(SEL)sel{
    
    
    UIButton *but=[self itemWithImageName:imageName target:target sel:sel];
    [but setImage:[UIImage imageNamed:seletImageName] forState:UIControlStateHighlighted];
    //包装一层view
    UIView *view=[[UIView alloc] initWithFrame:but.frame];
    [view addSubview:but];
    
    return [[UIBarButtonItem alloc] initWithCustomView:view];
}
+(UIButton *)itemWithImageName:(NSString *)imageName target:(id)target sel:(SEL)sel{
    
    UIButton *but=[UIButton buttonWithType:UIButtonTypeCustom];
    [but setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [but addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    [but sizeToFit];
    
    return but;
}
+(instancetype)itemWithImageName:(NSString *)imageName hileghtImageName:(NSString *)hileghtImageName target:(id)target sel:(SEL)sel{
    
    
    UIButton *but=[self itemWithImageName:imageName target:target sel:sel];
    [but setImage:[UIImage imageNamed:hileghtImageName] forState:UIControlStateSelected];
    //包装一层view
    UIView *view=[[UIView alloc] initWithFrame:but.frame];
    [view addSubview:but];
    
    return [[UIBarButtonItem alloc] initWithCustomView:view];
}
@end
